/**
 * 
 */
package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.form.fields.SelectItem;

/**
 * @author dttgiang
 *
 */
public class TraineeDS extends PersonDS {

    private static TraineeDS instance;

    private TraineeDS() {
        super(Service.TRAINEE);

        DataSourceDateField baptismDate = new DataSourceDateField(Parameter.BAPTISM_DATE);
        DataSourceTextField baptismPlace = new DataSourceTextField(Parameter.BAPTISM_PLACE);
        DataSourceDateField confirmationDate = new DataSourceDateField(Parameter.CONFIRMATION_DATE);
        DataSourceTextField confirmationPlace = new DataSourceTextField(Parameter.CONFIRMATION_PLACE);
        DataSourceDateField firstCommunionDate = new DataSourceDateField(Parameter.FIRST_COMMUNION_DATE);
        DataSourceTextField firstCommunionPlace = new DataSourceTextField(Parameter.FIRST_COMMUNION_PLACE);

        SelectItem fatherEditor = new SelectItem(Parameter.FATHER);
        fatherEditor.setValueField(Parameter.ID);
        fatherEditor.setDisplayField(Parameter.FULL_NAME);
        fatherEditor.setOptionDataSource(ParentDS.getInstance());
        //fatherEditor.setWidth(250);
        fatherEditor.setDefaultToFirstOption(true);

        DataSourceTextField father = new DataSourceTextField(Parameter.FATHER);
        father.setValueXPath(combineXPath(Parameter.FATHER, Parameter.ID));
        father.setTypeAsDataSource(ParentDS.getInstance());
        father.setEditorType(fatherEditor);

        SelectItem motherEditor = new SelectItem(Parameter.MOTHER);
        motherEditor.setValueField(Parameter.ID);
        motherEditor.setDisplayField(Parameter.FULL_NAME);
        motherEditor.setOptionDataSource(ParentDS.getInstance());
        //motherEditor.setWidth(250);
        motherEditor.setDefaultToFirstOption(true);
        
        DataSourceTextField mother = new DataSourceTextField(Parameter.MOTHER);
        mother.setValueXPath(combineXPath(Parameter.MOTHER, Parameter.ID));
        mother.setTypeAsDataSource(ParentDS.getInstance());
        mother.setEditorType(motherEditor);

        SelectItem sponsorEditor = new SelectItem(Parameter.SPONSOR);
        sponsorEditor.setValueField(Parameter.ID);
        sponsorEditor.setDisplayField(Parameter.FULL_NAME);
        sponsorEditor.setOptionDataSource(ParentDS.getInstance());
        //sponsorEditor.setWidth(250);
        sponsorEditor.setDefaultToFirstOption(true);

        DataSourceTextField sponsor = new DataSourceTextField(Parameter.SPONSOR);
        sponsor.setValueXPath(combineXPath(Parameter.SPONSOR, Parameter.ID));
        sponsor.setTypeAsDataSource(ParentDS.getInstance());
        sponsor.setEditorType(sponsorEditor);

        SelectItem statusEditor = new SelectItem(Parameter.STATUS);
        statusEditor.setRequired(true);
        statusEditor.setValueField(Parameter.ID);
        statusEditor.setDisplayField(Parameter.NAME);
        statusEditor.setOptionDataSource(TraineeStatusDS.getInstance());
        //statusEditor.setWidth(250);
        statusEditor.setDefaultToFirstOption(true);

        DataSourceTextField status = new DataSourceTextField(Parameter.STATUS);
        status.setValueXPath(combineXPath(Parameter.STATUS, Parameter.ID));
        status.setTypeAsDataSource(TraineeStatusDS.getInstance());
        status.setEditorType(statusEditor);
/*
        SelectItem doctrineClassEditor = new SelectItem(Parameter.CURRENT_DOCTRINE_CLASS);
        doctrineClassEditor.setRequired(true);
        doctrineClassEditor.setValueField(Parameter.ID);
        doctrineClassEditor.setDisplayField(Parameter.NAME);
        doctrineClassEditor.setOptionDataSource(DoctrineClassDS.getInstance());
        doctrineClassEditor.setWidth(250);
        doctrineClassEditor.setDefaultToFirstOption(true);

        DataSourceTextField currentDoctrineClass = new DataSourceTextField(Parameter.CURRENT_DOCTRINE_CLASS);
        currentDoctrineClass.setValueXPath(combineXPath(Parameter.CURRENT_DOCTRINE_CLASS, Parameter.ID));
        currentDoctrineClass.setTypeAsDataSource(DoctrineClassDS.getInstance());
        currentDoctrineClass.setEditorType(doctrineClassEditor);
*/
        addField(baptismDate);
        addField(baptismPlace);
        addField(confirmationDate);
        addField(confirmationPlace);
        addField(firstCommunionDate);
        addField(firstCommunionPlace);
        addField(father);
        addField(mother);
        addField(sponsor);
        addField(status);
//        addField(currentDoctrineClass);
    }

    @Override
    public int getType() {
        return Parameter.PersonType.TRAINEE_TYPE;
    }

    public static TraineeDS getInstance() {
        if (instance == null) {
            instance = new TraineeDS();
        }

        return instance;
    }
}
